package com.wan37.logic.tradingshop.service.impl;

import com.wan37.logic.tradingshop.dao.TradingShopDao;
import com.wan37.logic.tradingshop.dao.TradingShopRecordDao;
import com.wan37.logic.tradingshop.domain.entity.TradingShopRecordDO;
import com.wan37.logic.tradingshop.domain.vo.TradingShopRecordVO;
import com.wan37.logic.tradingshop.domain.vo.TradingShopVO;
import com.wan37.logic.tradingshop.service.TradingShopRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

/**
 * @author : luoyong
 * @date : 2020-08-05 16:14
 **/
@Service("tradingShopRecordService")
public class TradingShopRecordServiceImpl implements TradingShopRecordService {
    @Autowired
    private TradingShopRecordDao tradingShopRecordDao;
    @Override
    public List<TradingShopRecordVO> findByTradingShopId(String tradingShopId) {
        List<TradingShopRecordDO> tradingShopRecordDOList = tradingShopRecordDao.findByTradingShopId(tradingShopId);
        if (tradingShopRecordDOList == null){
            return null;
        }
        List<TradingShopRecordVO> tradingShopRecordVOList = new LinkedList<>();
        for (TradingShopRecordDO tradingShopRecordDO : tradingShopRecordDOList){
            TradingShopRecordVO tradingShopRecordVO = new TradingShopRecordVO(tradingShopRecordDO);
            tradingShopRecordVOList.add(tradingShopRecordVO);
        }
        return tradingShopRecordVOList;
    }

    @Override
    public List<TradingShopRecordVO> findByUserId(String userId) {
        List<TradingShopRecordDO> tradingShopRecordDOList = tradingShopRecordDao.findByUserId(userId);
        List<TradingShopRecordVO> tradingShopRecordVOList = null;
        if (tradingShopRecordDOList != null){
            tradingShopRecordVOList = new LinkedList<>();
            for (TradingShopRecordDO tradingShopRecordDO : tradingShopRecordDOList){
                TradingShopRecordVO tradingShopRecordVO = new TradingShopRecordVO(tradingShopRecordDO);
                tradingShopRecordVOList.add(tradingShopRecordVO);
            }
        }
        return tradingShopRecordVOList;
    }

    @Override
    public List<TradingShopRecordVO> findByBuyId(String buyId) {
        List<TradingShopRecordDO> tradingShopRecordDOList = tradingShopRecordDao.findByBuyId(buyId);
        List<TradingShopRecordVO> tradingShopRecordVOList = null;
        if (tradingShopRecordDOList != null){
            tradingShopRecordVOList = new LinkedList<>();
            for (TradingShopRecordDO tradingShopRecordDO : tradingShopRecordDOList){
                TradingShopRecordVO tradingShopRecordVO = new TradingShopRecordVO(tradingShopRecordDO);
                tradingShopRecordVOList.add(tradingShopRecordVO);
            }
        }
        return tradingShopRecordVOList;
    }

    @Override
    public boolean update(TradingShopRecordVO tradingShopRecordVO) {
        return tradingShopRecordDao.update(new TradingShopRecordDO(tradingShopRecordVO));
    }

    @Override
    public boolean save(TradingShopRecordVO tradingShopRecordVO) {

        return tradingShopRecordDao.add(new TradingShopRecordDO(tradingShopRecordVO));
    }

    @Override
    public boolean delete(TradingShopRecordVO tradingShopRecordVO) {
        return false;
    }
}
